#include "Comm.hpp"
#include "Fifo.hpp"
int main()
{
    // 1.获取key
    key_t key = GetShmKeyOrDie();
    cout << "key: " << ToHex(key) << endl;

    // 2.创建共享内存
    int shmid = CreateShm(key, defaultsize);
    cout << "shmid: " << shmid << endl;
    // sleep(2);

    // ShmDebug(shmid);

    // 4.将共享内存和进程挂接(关联)
    char *addr = (char *)ShmAttach(shmid);
    cout << "Attach shm success, adde: " << ToHex((uint64_t)addr) << endl;


    // 0.先引入管道
    Fifo fifo;
    Sync syn;
    syn.OpenReadOrDie();

    // 可以通信了
    for (;;)
    {
        if(!syn.Wait())
            break;
        cout << "shm content: " << addr << endl;
    }

    ShmDetach(addr);
    cout << "Detach shm success, adde: " << ToHex((uint64_t)addr) << endl;

    // 3.删除共享内存

    DeleteShm(shmid);
    return 0;
}